import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("动态更新模型")

    ComboBox {
        id: dynamicCombo
        width: 200
        anchors.centerIn: parent

        Component.onCompleted: {
            // 模拟异步加载数据
            Qt.callLater(function() {
                dynamicCombo.model = ["动态加载1", "动态加载2", "动态加载3"]
            })
        }

        Button {
            anchors.left: parent.right
            anchors.leftMargin: 10
            text: "添加选项"
            onClicked: {
                if (dynamicCombo.model instanceof Array) {
                    var newModel = dynamicCombo.model.slice()
                    newModel.push("新选项" + (newModel.length + 1))
                    dynamicCombo.model = newModel
                }
            }
        }
    }
}
